package com.lill.sale.web;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.lill.common.component.util.R;
import com.lill.sale.service.IDiscountOfSaleService;
import com.lill.support.annotation.CurrentUser;
import com.lill.system.model.SysUserEntity;

/**
 * 车辆返利值Controller
 *
 * @author lill
 * @date 2021-09-06 20:23:17
 */
@RestController
@RequestMapping("sale/discount")
public class SaleDiscountController {
	
    @Autowired
    private IDiscountOfSaleService discountOfSaleService;

    /**
     * 查看信息
     */
    @RequestMapping("/info")
    public R info(@RequestParam String saleCarId,@RequestParam String productCarId) {
        Map<String, Object> discountMap = discountOfSaleService.queryObject(saleCarId,productCarId);
        return R.ok().put("productDiscount", discountMap);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody Map<String, Object> productDiscount,@CurrentUser SysUserEntity user) {
    	productDiscount.put("company_id", user.getCompanyId());
    	productDiscount.put("branch_id", user.getBranchId());
        int result=discountOfSaleService.save(productDiscount);
		if(result>0){
        	return R.ok();
        }else{
        	return R.failure();
        }
    }

}
